<?php
/**
 * 补交款
 */
class Application_Model_Arrears extends Application_Model_DomainObject{
    protected $_id;
    protected $_dateCreated;//创建时间
    protected $_type;//类型
    protected $_relevantId;//关联id
    protected $_arrearsMoney;//补交金额
    protected $_arrearsUrl;//补交金额路径
    protected $_datePaid;//付款时间
    protected $_status;//状态是否补交（1补交2否）
    /**
     * 上门取件
     */
    const Type_Visiting = 1;
    
    public static function AddArrears($relevantId,$arrearsMoney,$arrearsUrl,$type = Application_Model_Arrears::Type_Visiting)
    {
        $arrearsItem = self::getItemByRelevantIdType($relevantId, $type);
        if($arrearsItem){
            $arrearsItem = new Application_Model_Arrears();
        }
        $arrearsItem->relevantId = $relevantId;
        $arrearsItem->arrearsMoney = $arrearsMoney;
        $arrearsItem->arrearsUrl = $arrearsUrl;
        $arrearsItem->type = $type;
        $arrearsItem->dateCreated = date("Y-m-d H:i:s");
        $arrearsItem->save();        
    }
    
    public static function getItemByRelevantIdType($relevantId,$type = Application_Model_Arrears::Type_Visiting)
    {
        $where[" relevantId = "] = $relevantId;
        $where[" and type = "] = $type;
        return self::getDao()->queryOne($where);
    }
}